//
//  LLPlaceholderTextView.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/11/4.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit

class LLPlaceholderTextView: UITextView {

    
    
    var placeholder:String?{
        didSet{
            placeholerLabel.text = placeholder
            
            placeholerLabel.font = font
            
            placeholerLabel.sizeToFit()
        
        }
    }
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        
        prepareUI()
        
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange", name: UITextViewTextDidChangeNotification, object: self)
    }
    
    deinit{
        
        NSNotificationCenter.defaultCenter().removeObserver(self)
    
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK通知方法不能为私用
    func textDidChange(){
        
        placeholerLabel.hidden = hasText()
        
    
    }
    
    private func prepareUI(){
        
        addSubview(placeholerLabel)
        
        placeholerLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: nil,offset: CGPoint(x: 5, y: 8))
    
    }
    
    private lazy var placeholerLabel:UILabel = {
        let label = UILabel(fonsize: 18, textColoc: UIColor.grayColor())
        
        return label
    }()
}
